import { DataQueryPage, ImageItemType, FormBox, TableBox, BasicFormBox } from "@pkg";
interface TestForm {
	cascader: string[];
	select: string;
}
interface TestTable {
	name: string;
	name1: string;
	name2: number;
	name3: "Y" | "N";
	name4: number;
	id: string;
	hasChildren?: boolean;
	children?: TestTable[];
}
export default class Test1Page extends DataQueryPage<TestForm, TestTable> {
	constructor() {
		super("test5", "/page/#pageNum#/#pageSize#/classfiy");
	}
	initForm(form: BasicFormBox<TestForm>): void {
		let id = 0;
		form.addFormItem({
			component: "Cascader",
			key: "cascader",
			label: "级联123123",
			value: ["opt_0__1", "opt_1__5", "opt_2__8"],
			rule: "RequiredRule",
			placeholder: "请选择级联",
			conf: {
				change: () => {
					this.setFormConf("select", {
						component: "Select",
						conf: {
							options: [
								{ label: "zhangsan1", value: "11" },
								{ label: "lisi1", value: "21" },
								{ label: "wangwu1", value: "31" },
							],
						},
					});
				},
				lazy: {
					lazy: true,
					lazyLoad(node, resolve) {
						const list = Array.from({ length: 3 }, () => ({
							label: "opt_label" + node.level + "__" + id++,
							value: "opt_" + node.level + "__" + id,
							leaf: node.level >= 2,
						}));
						resolve(list);
					},
				},
			},
		});
		form.addFormItem({
			key: "select",
			component: "Select",
			label: "下拉选择",
			placeholder: "请选择下拉选择",
			value: "",
			conf: {
				options: () =>
					Promise.resolve([
						{ label: "zhangsan", value: "1" },
						{ label: "lisi", value: "2" },
						{ label: "wangwu", value: "3" },
					]),
			},
		});
	}
	initTable(table: TableBox<TestTable>): void {
		table.setTableSource(
			Array.from({ length: 10 }, _ => {
				return {
					name: "https://ecmb.bdimg.com/tam-ogel/1815134652_-1760084283_1200_1200.png",
					name1: "测试数据" + Math.random(),
					name2: 23293802,
					name3: "N",
					name4: 2500,
					id: "1-2" + Math.random() + new Date().getTime(),
					hasChildren: true,
				};
			})
		);
		table.setChildTable({
			rowKey: "id",
			children: "children",
			lazy: true,
			hasChildren: "hasChildren",
			load: (_row, _treeNode, resolve) => {
				setTimeout(() => {
					resolve([
						{
							name: "https://ecmb.bdimg.com/tam-ogel/1815134652_-1760084283_1200_1200.png",
							name1: Math.random() > 0.5 ? "测试数据" : "",
							name2: 23293802,
							name3: "N",
							name4: 2500,
							id: "1-2" + Math.random() + new Date().getTime(),
							hasChildren: true,
						},
					]);
				}, 200);
			},
		});

		table.setTableSelection(true);
	}
}
